<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="../Main/top.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="/WEB-INF/CustomTag" prefix="customTag"%>
<script type="text/javascript" src="CourseFileSrcCatePrivate.js"></script>
<script type="text/javascript">
	$(document).ready( function() {
		courseFileCateParentIdChange();
		isPreCourseCateClick();
		queryCourseList();

		//如果为预置分类隐藏课程选项
		if(${courseFileSrcCatePrivate.isPreCourseCate}==1){
			$("#courseIdLine").hide();
		}else if(${courseFileSrcCatePrivate.isPreCourseCate}==0){
			$("#courseIdLine").show();
			$("#courseId").addClass("required");
		}
		//除根分类外隐藏预置设置选项
		if(${courseFileSrcCatePrivate.courseFileCateParentId}!=-1){
			$("#isPreCourseCateLine").hide();
		}
	});
	
	//父分类ID改变激活事件
	function courseFileCateParentIdChange() {
		$("#courseFileCateParentId").change(function() {
			if ($("#courseFileCateParentId").attr("value") != -1) {
				getParentCateIsPre();
			} else if ($("#courseFileCateParentId").attr("value") == -1) {
				$("#isPreCourseCate0").attr("checked", false)
				$("#isPreCourseCate1").attr("checked", false)
				$("#isPreCourseCateLine").show();
				$("#courseIdLine").show();
				$("#courseIdNull").attr("selected",true);
				$("#depth").attr("value",1);
			}
		});
	}

	//获取是否为预置分类并根据其设置当前分类值
	function getParentCateIsPre(){
		var courseFileCateParentId = document.getElementById("courseFileCateParentId").value;
		if(courseFileCateParentId!=""){
			$.post(
					"../AjaxResultData/checkParentCateIsPreCoursePrivate.action",
					{"courseFileSrcCatePrivate.courseFileCateId":courseFileCateParentId},
					function(data){
						var isNotUsedData = eval("("+data.isNotUsedData+")");
						if(isNotUsedData[0].isNotUsed==0){
							$("#isPreCourseCate0").attr("checked", true);
							$("#isPreCourseCateLine").hide();
							$("#courseIdLine").hide();
						}else if(isNotUsedData[0].isNotUsed==1){
							$("#isPreCourseCate1").attr("checked", true);
							$("#isPreCourseCateLine").hide();
							$("#courseIdNull").attr("selected",true);
							$("#courseIdLine").hide();
						}
						$("#courseId").attr("value",isNotUsedData[0].cateId);
						$("#depth").attr("value",(parseInt(isNotUsedData[0].parentDepth)+1));
					},
					"json"
			);
		}
	}
	
	function isPreCourseCateClick(){
		$("#isPreCourseCate1").click(function(){
			$("#courseIdNull").attr("selected",true);
			$("#courseIdLine").hide();
			$("#courseId").removeClass("required");
		});
		$("#isPreCourseCate0").click(function(){
			$("#courseIdLine").show();
			$("#courseId").addClass("required");
		});
	}
	function queryCourseList(){
		$.post(
			"../AjaxResultData/listAllCourse.action",
			function(data){
				var courseData = eval("("+data.courseData+")");
				for(var i = 0; i<courseData.length; i++){
					if(${courseFileSrcCatePrivate.courseId} == courseData[i].courseId){
						$('#courseId').append("<option value='"+courseData[i].courseId+"' selected='selected'>"+courseData[i].courseName+"</option>");
					}else{
						$('#courseId').append("<option value='"+courseData[i].courseId+"'>"+courseData[i].courseName+"</option>");
					}
				}
			}
		);
	}
</script>
<div class="function_title"><span class="t2"><img src="../images/dqwz.gif">当前位置：编辑分类信息</span></div>
<div class="function_content">

<div class="addItem"><img src="../images/return_icon.png"><a href="listCourseFileSrcCatePrivate.action?intercept=1">返回列表</a></div>

<span class="important_info">注：带*项为必填信息!</span>
<form action="updateCourseFileSrcCatePrivate.action" method="post" id="demo" >
<s:hidden name="courseFileSrcCatePrivate.courseFileCateId"></s:hidden>
<input type="hidden" name="courseFileSrcCatePrivate.depth" id="depth" value="<s:property value='courseFileSrcCatePrivate.depth'/>"> 
  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="loginTable">
    <tr>
      <td width="14%" align="right" class="leftBg"><span class="important_info">*</span>分类名称：</td>
      <td width="86%"><s:textfield name="courseFileSrcCatePrivate.courseFileCateName" id="courseFileSrcCatePrivate.courseFileCateName"></s:textfield></td>
    </tr>
    <tr>
      <td align="right" class="leftBg"><span class="important_info">*</span>所属父分类：</td>
      	<td>
<customTag:treeSelectorCoursePrivate courseFileCateId="${courseFileSrcCatePrivate.courseFileCateParentId}" type="courseFileSrcCatePrivate" selectName="courseFileCateParentId" notNeedValidation="false" target="false"></customTag:treeSelectorCoursePrivate>
		</td>
    </tr>
    <tr id="isPreCourseCateLine">
      <td align="right" class="leftBg"><span class="important_info">*</span>是否为预置分类：</td>
      <td>
<s:if test="%{courseFileSrcCatePrivate.isPreCourseCate==1}">
<input type="radio" name="courseFileSrcCatePrivate.isPreCourseCate" value="1" class="no_border" id="isPreCourseCate1" checked="checked">是
<input type="radio" name="courseFileSrcCatePrivate.isPreCourseCate" value="0" class="no_border" id="isPreCourseCate0">否
</s:if>
<s:elseif test="%{courseFileSrcCatePrivate.isPreCourseCate==0}">
<input type="radio" name="courseFileSrcCatePrivate.isPreCourseCate" value="1" class="no_border" id="isPreCourseCate1" >是
<input type="radio" name="courseFileSrcCatePrivate.isPreCourseCate" value="0" class="no_border" id="isPreCourseCate0" checked="checked">否
</s:elseif>
<span id="errMsg"></span>
</td>
    </tr>
    <tr id="courseIdLine">
      <td align="right" class="leftBg"><span class="important_info">*</span>所属课程：</td>
      <td>
		<select name="courseFileSrcCatePrivate.courseId" id="courseId">
			<option value="" id="courseIdNull">--未选择--</option>
		</select>
	</td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td>
        <input type="submit" name="submit" id="submit" value="提交" class="deal_button">
      </td>
    </tr>
  </table>
</form>

</div>

<%@ include file="../Main/bottom.jsp"%>
